package top.wettis.chat.controller;

import cn.hutool.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.wettis.chat.constant.ResultType;
import top.wettis.chat.pojo.DO.Expert;
import top.wettis.chat.pojo.DO.Occupation;
import top.wettis.chat.pojo.DO.User;
import top.wettis.chat.pojo.VO.Result;
import top.wettis.chat.service.IExpertService;
import top.wettis.chat.service.IOccupationService;
import top.wettis.chat.service.IUserService;

import java.util.List;

@RestController
@CrossOrigin

@RequestMapping("/chat")
public class CountController {
    @Autowired
    private IUserService userService;

    @Autowired
    private IExpertService expertService;

    @Autowired
    private IOccupationService occupationService;

    @GetMapping("/total")
    public Result<Object> count() {
        List<User> userList = userService.list();
        List<Expert> expertList = expertService.list();
        List<Occupation> occupationList = occupationService.list();
        int total = userList.size() + expertList.size() + occupationList.size() + 18;

        JSONObject jsonObject = new JSONObject();
        jsonObject.putOpt("userRate", userList.size() * 100.0 / total);
        jsonObject.putOpt("expertRate", expertList.size() * 100.0 / total);
        jsonObject.putOpt("occupationRate", occupationList.size() * 100.0 / total);
        jsonObject.putOpt("devRate", 13 * 100.0 / total);
        jsonObject.putOpt("csRate", 5 * 100.0 / total);
        return Result.successInfo(ResultType.GET, jsonObject);
    }
}
